package myauth

import (
	"public/tools"
)

//多角色权限判断（不支持topic/bundle/pid）
func CheckRoleAuth(rolestr string, module string, levels ...string) bool {
	var roles []RoleDesc
	tools.JsonEncode(rolestr, &roles)

	if len(roles) > 0 {
		for _, v := range roles {
			//权限检验
			tmp_u := UserInfo{Business_role: v.Role, Topic: "", Bundle: "", Pid: ""}
			if CheckUserAuth(tmp_u, module, levels...) {
				return true
			}
		}
	}
	return false
}

//单角色权限判断（支持topic/bundle/pid）
func CheckSingleRoleAuth(role int, topic, bundle, pid, module string, levels ...string) bool {
	//权限检验
	tmp_u := UserInfo{Business_role: role, Topic: topic, Bundle: bundle, Pid: pid}
	return CheckUserAuth(tmp_u, module, levels...)
}
